package org.spbsu.apco.common.task.impl.matrix;

import org.spbsu.apco.common.data.core.DurationEstimable;
import org.spbsu.apco.common.data.impl.Matrix;
import org.spbsu.apco.common.task.core.BaseTask;

import java.util.List;

/**
 * User: ortemij
 * Date: 07.01.13
 * Time: 14:57
 */
public class MatrixConstructionTask extends BaseTask<Double[], Matrix> implements DurationEstimable<Double[]> {

    @Override
    public Matrix execute(final List<Double[]> inputData) throws Exception {
        final int n = inputData.size();
        final int m = inputData.get(0).length;
        Matrix a = new Matrix(n, m);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                a.set(i, j, inputData.get(i)[j]);
            }
        }
        return a;
    }

    @Override
    public int estimateDuration(List<Double[]> arguments) {
        return arguments.isEmpty() ? 1 : arguments.size() * arguments.get(0).length;
    }
}
